package dianmobile.eistarandroid.network.request;

import android.content.Context;
import com.android.volley.Response;
import org.xmlpull.v1.XmlPullParser;
import java.util.Map;

import dianmobile.eistarandroid.utils.ConstantsData;

/**
 * 获取是否有新信件
 * Created by dianmobile_yy on 15/11/18.
 */
public class MyNewMailsRequest extends ByhhAndroidRequest{


    public static void execute(Context context, RequestCallback callback) {
        executeSuper(context, RequestType.MY_NEW_MAILS, null, callback);
    }

    public MyNewMailsRequest(int method, String url,  Map<String, String> params, RequestCallback callback, Response.ErrorListener errorListener) {
        super(method, url, params, callback, errorListener);
    }

    @Override
    protected void parseXmlToMap(XmlPullParser parser, Map<String, Object> result) {
        final String TAG_MSG = "msgs";
        try {
            int event = parser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch (event) {
                    case XmlPullParser.START_TAG:
                        String tag = parser.getName();
                        if (tag.equals(TAG_MSG)) {
                            if (Integer.parseInt(parser.getAttributeValue(null, "newmail")) == 1) {
                                result.put(ConstantsData.RESULT_DATA, true);
                            } else {
                                result.put(ConstantsData.RESULT_DATA, false);
                            }
                        }
                        break;
                    default:
                        break;
                }
                event = parser.next();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
